import random
import cv2
import numpy as np
import shutil

def Merge(background, foreground, rect):
    fg = cv2.resize(foreground, (rect[2], rect[3]))
    background[rect[1]:rect[1] + rect[3], rect[0]:rect[0] + rect[2], :] = fg
    return background

img = cv2.imread('2.jpg')
img1 = cv2.imread('panda.jpg')
rect = (300, 200, 100, 50) # x, y, width, height
M = Merge(img, img1, rect)
cv2.imshow('image', M)
cv2.waitKey()